<?                                      
$cmp_sort_key = get_profile_value($host, "listsort");                                   
if ($cmp_sort_key=="") $cmp_sort_key="size";                                 
                                                                                                                     
#BEGIN PAGE FORM                                                                          
print "<form action='" . $href . "?sub=".$sub."&cat=".$cat."' method='post' style='margin:0'>  ";                                                                                                                                                   


$cats = "<div style='border-top:solid 1px white;border-bottom:solid 1px silver'>&nbsp;";                                                                                                                                                   
$vats = "&nbsp;";                                                                                                                                                   
 while (list($a,$b)=each($categories))                                                                                                                                                   
 {                                                                                                                                                   
     $line = "<a href='" . $href . "?sub=all&cat=".  $a . "'                                                                                                                                                   
            " . ($a==$cat?"style='background-color:white;padding:1px'":"") . "><font color='#666666' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
            >" . $a . "</font></a>";                                                                                                                                                    
     $cats .= $line . "&nbsp;<label disabled>|</label>&nbsp;";                                                                                                                                                   
     $vats .= "<li>" . $line;                                                                                                                                                   
 }                                                                                                                                                   

 $cats .= "<a href='" . $href . "?sub=all'                                                                                                                                                   
        " . (""==$cat?"style='background-color:white;padding:1px'":"") . "><font color='#666666' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
        >Subscribed Groups</font></a>&nbsp;<label disabled>|</label>&nbsp;";                                                                                                                                                   
                                                                                                                                                           
print $cats;                                                                                                                                                   

print "<font color='#666666' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
            >    &nbsp;    Find:  <input type='text' size='10' value='".$find_name."' name='f' align='absmiddle'>                                                                                                                                                   
          <input type='image' src='images/search_btn.png' align='absmiddle' value='Search'> <!-- <input type=checkbox name=findall>Search all selected groups -->                                                                                                                                                  
          </div>&nbsp;To subscribe to any group, check the box next to it and click                                                                                                                                                    
          <input type='image' align='absmiddle'                                                                                                                                                   
  src='image.php?b=Subscribe&h=24&w=100&i=usenet'                                                                                                                                                   
  border='0'>                                                                                                                                                    
         </font>";                                                                                                                                                   

print "<div style='background-color:white;                                                                                                                                                   
            height:expression (document.body.offsetHeight-24);margin:2px'                                                                                                                                                   
            class='resizeXY'>";                                                                                                                                                    

$html = "<table width='800' align='center' cellpadding='2' cellspacing='2' class='bevel' style='margin-bottom:5px;margin-top:5px'>";                                                                                                  
$html .= "<tr><td><font size=2 face='Verdana, Arial, Helvetica, sans-serif' color='#ffffff'>";                                                                                                  
$html .= "<b>" . ( $find_name==""?"Subscribed groups":"Groups like '" . $find_name . "'" ) . "</b>";                                                                                                  
$html .= "</font></td></tr></table>";                                                   
                                                                                                                                             
                                                                                                                                                    
#print_r ($sg_s);                                                                                                                                                   
$ss = $_GET["ss"];                                                                                                                                                    
$sc = $_GET["cat"];                                                                                
                                                                                                                                             
echo $find_name;
                                                                                                                                                    
if ($sc=="")                                                                                                                                                   
{  # simple search                                                                                
                                                                                                                                             
    if ($find_name=="")                                                                                                                                                   
    { # if no search params are received, use the server list in the cache                                                                                                                                                   
        $group_list = $sg_c;                                                                                                                                                    
    }                                                                                                                                                    
                                                                                                                                                           
    if ($find_name!="")                                                                                                                                                   
    { # search param received                                                                                                                                                    
        $group_list = array ();                                                                                                                                                    
                          $nntp=force_connect();                                                                                                                                     
        # build gmat search string from the param                                                                                                                                                   
        $pp_reg="/.*(".$find_name.").*\s+(\d+)\s+(\d+)\s+/";                                                                                                                                                                                                                           
        $group_list=nntp_load_list ($nntp_server);                                                                            
        $group_list = nntp_group_list ($group_list,$pp_reg);                                                                                                                                            

                                                                
        uasort ($group_list,cmp_by_size);                                     
        $tmp_arr=array();                                   
        foreach ($group_list as $tmp_item) $tmp_arr[] = $tmp_item;                                   
        $group_list = $tmp_arr;                                                                                                                                                   
                                                                                                                   
        # result list ----------------------------------------------------'                                                        
        print "<table border=0 align='center' width=800 class=bevel2><tr><td>";                                                                                                    
        echo "  <table width='800' align='center' cellpadding='2' cellspacing='2' class='bevel' style='margin-bottom:5px;margin-top:5px'>";                                                                                                  
        echo "   <tr><td>";                                                                                                  
        echo "    <font size=2 face='Verdana, Arial, Helvetica, sans-serif' color='#ffffff'><b>Newsgroups on $nntp_server like '$find_name'</b></font>";                                                                                                  
        echo "   </td></tr>";                                                                                                  
        echo "  </table><center><img src='image.php?f=f' id='istrip' onmouseover=\"this.src=this.src\"></center>&nbsp;&nbsp;";                                                                                                                                                                             
        $all_pages = pagination ($group_list,$start_at,"&sub=all&f=" . $find_name );                                                           

        $first_page = $all_pages["begin"];                                                                                                                                                                                                                                                             
        $last_page  = $all_pages["end"];                                                            

                             
                                                                                                                                     
        $cookie_view = get_profile_value($host, "listsort");                       
        if ($cookie_view=="group")                                
        {                                  
            echo "&nbsp;&nbsp;Sort by: <b>Name</b>  <a href=\"javascript:fb_edit('a','changesort', 'f', '$find_name')\">Size</a>";                                  
        }                                
        else                                
        {                                
            echo "&nbsp;&nbsp;Sort by: <a href=\"javascript:fb_edit('a','changesort', 'f', '$find_name')\">Name</a>  <b>Size</b>";                                
        }                         
                                                                                                                                                       
        print "<table>";                                                                                                                                      
        for ($w=$first_page;$w<$last_page;$w++)                                                                                                                                                      
        {                                                                                                                                                   
            $buf=$group_list[$w];                                                                        
            $caption=$buf["caption"];                                                                                                                                                 
            $color=$buf["color"];                                                                                                                                                 
            $groupid=$buf["group"];                                                                                                                                                 
            $size=$buf["size"];                                                                       
            print "<tr>";                                                                                                                                                   
            print "<td><input value='".$groupid."' type=checkbox name='subscribe[]'></td>                                                                                                                                                   
                          <td nowrap><a " . $color . " href='".$href."?g=".$groupid."&nntp=".$nntp_server."'                                                                                                                                                   
                            ><font color='#666666' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
                             >" . $caption . "</font>    </a></td>";                                                                                                                                                   
            print "<td><font color='#999999' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
                             >" . $size . "</font></td><td width='100%'>&nbsp;</td>";                                                                                                                                                   
            print "</tr>";                                                                                                                          
        }                                                                                                                                                   
         print "</table></td></tr></table>";                                                                                                                                                     
        # result list ----------------------------------------------------'                                                                                                                                                   
    }                                                                                                                                                   
    else if (isset($group_list) && is_array($group_list) && count($group_list)>0 && strlen(trim(implode('',$group_list)))>0)                                                                                                                                                   
    { # DEFAULT: subscribed groups                                                                                                                                                   
        debug ($nntp_server."--".$user."--".$pass."--".implode("\n",$group_list));                                                                                                                                                 
        reset ($categories);                                                                                                                             
        $group_results=array();                                                                                                                                
        $array = nntp_load_list ($nntp_server);                                                                         
                                                                
        # lookup ---------------------------------------------------------'                                                                                                                                                          
        echo "<table align='center' cellpadding='2' cellspacing='2' class='bevel2'>";                                                                                                  
        echo " <tr><td>";                                                                                                  
        echo "  <table width='800' align='center' cellpadding='2' cellspacing='2' class='bevel' style='margin-bottom:5px;margin-top:5px'>";                                                                                                  
        echo "   <tr><td>";                                                                                                  
        echo "    <font size=2 face='Verdana, Arial, Helvetica, sans-serif' color='#ffffff'><b>Top 10 Newsgroups on $nntp_server</b></font>";                                                                                                  
        echo "   </td></tr>";                                                                                                  
        echo "  </table><center><img src='image.php?f=f' id='istrip' onmouseover=\"this.src=this.src\"></center>";                                                                                                                                            

                                                                               
                                                                                                                         
        print "<table border=0 align='center'><tr>";                                                                                      
        while (list($x,$y)=each($categories))                                                                                                                                
        {                                                                                                                                  
                                                                                                                              
            $group_result=nntp_group_list ($array, $y[1]);                                                                                                                                         
            uasort ($group_result,cmp_by_size);                                                                                                                                            
            $group_count=0;                                                                                                                                        
            $group_rand = time() % 10;                                                                                                                                      
            $odd=true;                                                                                                                            
            print "<td valign='top'>";                                                                                                                                
            print "<table border=0>";                                                                                                                                
            print "<tr><td colspan='3' bgcolor='white'><b>$x</b></td></tr>";                                                                                                      
            foreach ($group_result as $result)                                                                                                                                                   
            {                                                                                                       
                                                                                                                                                              
                if ($result["size"]>0)                                                                                                                                                  
                {                                                                                                              
                    $odd=!$odd;                                                                                              
                    print "<tr bgcolor='".($odd?"white":"whitesmoke")."'>";                                                                                                                                                   
                    print "<td><input value='".$result["group"]."' type=checkbox name='subscribe[]'></td>                                                                                                                                                   
                          <td><a " . $result["color"] . " href='".$href."?g=".$result["group"]."&nntp=".$nntp_server."'                                                                                                                                                   
                            ><font color='#666666' face='Times New Roman, Times, serif' size='3' style='font:8pt tahoma'                                                                                                                                                   
                             >" . str_replace("alt.binaries.","a.b.",$result["caption"]) . "</font>    </a></td>";                                                                                                                                                   
                    print "<td><font color='#999999' face='Times New Roman, Times, serif' size='3' style='font:8pt tahoma'                                                                                                                                                   
                             >" . $result["size"] . "</font></td>";                                                                                                                                                   
                    print "</tr>";                                                                                            
                    debug ($result["group"]);                                                                                                                                         
                    $group_count++;                                                                                                                                         
                    if ($group_count > 10)    
                    {                                                                                         
                        print "<tr><td colspan='3' bgcolor='white' align='right'><a href='$href?sub=all&cat=$x' style='color:#000066'><u>Show All $x</u></a></td></tr>";   
                        break;   
                    }                                                                                                                                               
                 }                                                                                                                                                  
            }                                                                                                                                    
            print "</table> ";                                                                                                                                
            print "</td>";                                                                                                                                     
        }                                                                                                                                   
        print "</tr></table>";                                                    
                                                                                                                               
                                                                          
        $all_pages = pagination ($group_list,$start_at,"&sub=all&f=" . $find_name );                                                            
                                                                   
        $first_page = $all_pages["begin"];                                                                                                                                                                                                                                                             
        $last_page  = $all_pages["end"];                                                                                                                  
        sort ($group_list);                                                                                                                                                   
                                                                                                                                                           
                                                                                                                                                           
        $nntp=force_connect();                                                                                                                                            
        # result list ----------------------------------------------------'                                                           
        $html .= "<table border='0' align='center' width='800'>";                                               
        $html .= "<tr><td>&nbsp;</td><td>Name</td><td align='right'>Count</td>";                                               
        $html .= "<td align='right'>From</td><td align='right'>To</td><td>&nbsp;</td></tr>";                                                                                                                                                  
             for ($e=$first_page;$e<$last_page;$e++)                                                                                                                                                      
             {                                                                                                                                                   
                $gl=$group_list[$e];                                                                                                                                                   
                if ($gl!="")                                                                                                                                                   
                {                                                                                                                                                       
                                                                                                                                                                       
                    if ( $gi=$nntp->join_group($gl) )                                                                                                                                                   
                    {                                                                                                                                                      
                         $html .= "<tr>                                                                                                                                                    
                         <td><input value='".$gl."' type=checkbox name='subscribe[]'></td>                                                                                                                                                   
                         <td nowrap>                                                                                                                                                   
                             <a href='".$href."?g=".$gl."'><font face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
                               >".$gl."</font></a>                                                                                                                                                   
                         </td>                                                                                                                                                   
                         <td align=right>                                                                                                                                                   
                             <a><font color='#666666' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
                               >".$gi["count"]."</font></a>                                                                                                                                                   
                         </td>                                                                                                                                                   
                         <td align=right>                                                                                                                                                   
                             <a><font color='#666677' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
                               >".$gi["start_id"]."</font></a>                                                                                                                                                   
                         </td>                                                                                                                                                   
                         <td align=right>                                                                                                                                                   
                             <a><font color='#666677' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
                               >".$gi["end_id"]."</font></a>                                                                                                                                                   
                         </td> <td width='100%'>&nbsp;</td>                                                                                                                                                  
                              </tr>";                                                                                                                                                   
                    }                                                                                                                                                   
                    else                                                                                                                                                   
                    {                                                                                                                                                   
                         $html .= "<tr>                                                                                                                                                    
                         <td></td>                                                                                                                                                   
                         <td nowrap>                                                                                                                                                   
                             <a href='".$href."?g=".$gl."'><font face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
                               color='#666666'>".$gl."</font></a>                                                                                                                                                   
                         </td>                                                                                                                                                   
                         <td colspan='3'>                                                                                                                                                   
                             <a><font color='#666666' face='Times New Roman, Times, serif' size='3'                                                                                                                                                   
                               >N/A</font></a>                                                                                                                                                   
                         </td>  <td>&nbsp;</td>                                                                                                                                                 
                              </tr>";                                                                                                                                                   
                    }                                                                                                                                                      
                }                                                                                                                                                      
             }                                                                                                                                                    
             print $html . "</table>";                                                                                                                                          
             print "</td></tr></table>";          			 
			# print "<div style='width:800px' align='center'>";          			 
			# print "<hr noshade color='#009933' width='800' align='center'>";  	
			# print "News<i>Jet</i> &copy;2006 cyber8 netWorks";          			 
			# print "</div>        ";  	                                                                                                                                     
             # result list ----------------------------------------------------'                                                                                                                                                       
    }                                                                                                                                                    
    else                                                                                                                                                   
    {                                                                                                                                                   
        ?>                                                                                                                                                   
                                                                                                                                                           
           <img src="image.php?i=p"  align="left"/>                                                                                                                                                   
           <font size="3" color="#999999" face="Times New Roman, Times, serif">                                                                                                                                                   
           You have no subscribed groups. Subscribing to a newsgroup means that you                                                                                                                                                    
           can easily access its content without searches later. To view a complete                                                                                                                                                    
           list of newsgroups that are available for subscription, select one of the                                                                                                                                                    
           available categories or use the Search box to find groups.</font>                                                                                                                                                   
           &nbsp;                                                                                                                                                           
           <ul>                                                                                                                                                   
           <?= $vats ?>                                                                                                                                                   
           </ul>                                                                                                                                                   
        <?                                                                                                                                                   
    }                                                                                                                                                   
}                                                                                                                                                    
else                                                                                                                                                   
{ # predefined searches                                                                                                                                                    

        # lookup ---------------------------------------------------------'                                                                                                                                                          
        reset ($categories);                            
                                                                                                                          
        $cookie_view = get_profile_value($host, "listsort");                                
        $group_results=array();                                                                                                                                
        $array = nntp_load_list ($nntp_server);                                                                                 
        $y=$categories[$sc];                                           
        $x=$sc;                                                                                      
                                                                                                                                 
                                                                                                                              
        $group_result=nntp_group_list ($array, $categories[$sc][1]);                                                                                                                                         
        uasort ($group_result,cmp_by_size);                                     
        $tmp_arr=array();                                   
        foreach ($group_result as $tmp_item)                
        { #filter by search param where found              
            if ($find_name=="" || strpos(strtolower($tmp_item["group"]),strtolower($find_name))!==false)               
            {               
                $tmp_arr[] = $tmp_item;                           
            }                
        }                                 
        $group_result = $tmp_arr;                   
                          
                                                                                                                                     
        $group_count=0;                                                                                                                                        
        $group_rand = time() % 10;                                                                                                                                      
                                                                                                                                                      
        print "<table border=0 align='center' width=800 class=bevel2><tr>";                                                                                
        print "<td valign='top'>";                                           
        echo "<table width='800' align='center' cellpadding='2' cellspacing='2' class='bevel' style='margin-bottom:5px;margin-top:5px'>";                                                                                                  
        echo "<tr><td>";                                                                                                  
        echo "<font size=2 face='Verdana, Arial, Helvetica, sans-serif' color='#ffffff'><b>All Newsgroups in $sc on $nntp_server</b></font>";                                                                                                  
        echo "</td></tr>";                                                                                                  
        echo "</table><div><img src='image.php?f=f'></div>";                                                                                                                                            
        if ($cookie_view=="group")                                
        {                                  
            echo "Sort by: <b>Name</b>  <a href=\"javascript:fb_edit('a','changesort')\">Size</a>";                                  
        }                                
        else                                
        {                                
            echo "Sort by: <a href=\"javascript:fb_edit('a','changesort')\">Name</a>  <b>Size</b>";                                
        }                                                                                                                      
                                     
        $all_pages = pagination ($group_result,$start_at,"&sub=all&cat=" . $sc, 10 );                           
        $first_page = $all_pages["begin"];                                                                                                                                                                                                                                                             
        $last_page  = $all_pages["end"];                                                            
        print "<table border=0>";                                       
                                                                                                                                               
        # result list ----------------------------------------------------'                                                                                
        $odd=true;                                
        print "<table width='800' cellspacing='0'>";                                                                                                                                      
        for ($w=$first_page;$w<$last_page;$w++)                                                                                                                                                      
        {                                          
             $result = $group_result[$w];                                                                                                            
             $odd=!$odd;                                                                                              
             print "<tr bgcolor='".($odd?"white":"whitesmoke")."'>";                                                                                                                                                   
             print "<td><input value='".$result["group"]."' type=checkbox name='subscribe[]'></td> ";                                                                                                                                                   
             print "<td><a " . $result["color"] . " href='".$href."?g=".$result["group"]."&nntp=".$nntp_server."'";                                                                                                                                                   
             print "><font color='#666666' style='font:8pt tahoma'>" . str_replace("alt.binaries.","a.b.",$result["caption"]) . "</font>    </a></td>";                                                                                                                                                   
             print "<td><font color='#999999' style='font:8pt tahoma'>" . $result["size"] . "</font></td>";                                                                                                                                                   
             print "<td><font color='#999999' style='font:8pt tahoma'>" . $result["first"] . "</font></td>";                                                                                                                                                   
             print "<td><font color='#999999' style='font:8pt tahoma'>" . $result["last"] . "</font></td><td width=100%>&nbsp;</td>";                                                                                                                                                   
             print "</tr>";                                                                                            
             debug ($result["group"]);                                                                                                                                                                                                                                           
        }                                                                                                                                                                                                              
        print "</table><br><br><br>";                                                                                                                                
        print "</td>";                                                                                                                                     
        print "</tr></table>";                                                                                                                                              
}                                                                                                                                                   
?>                                                                                                                                                   
</div>                                                                                                                                                   
</form>